/*-\|/-\|/-\|/-\|/
Support File of 
PCB functions for R2 

Version 1.0
|/-\|/-\|/-\|/-\*/

#include "mrj_supt.h"
#include <mpx_supt.h>

void setPCB(char* name, int priority, int Pclass){
	//Allocate memory for PCB
	struct pcb *newPCB;
	newPCB = &(allocPCB());
	//Compare name string using findPCB function to check if name is unique
	if(strcmp(name,find_PCB(name))){
		printf("ERROR: Process already exists");
		return 0;
	}
	else
		strcpy(newPCB.name, name);
	//Check to see if priority is valid; between -128 and 127
	if((priority < -128) || (priority > 127)){
		printf("ERROR: Process priority is invalid, please enter a value"+
		       "between -128 and 127");
		return 0;
	}
	else
		newPCB.priority = priority;
	//Check to see if the PCB Class is valid 
	if((Pclass != PCB_CLASS_SYSTEM) || (Pclass != PCB_CLASS_APP)){
		printf("ERROR: Process class is invalid, please enter a correct value:"+
		       "0 for System Process, 1 for Application Process");
		return 0;
	}
	else
		newPCB.Pclass = Pclass;
	//Set up initial states
	newPCB.state = PCB_STATE_RUN;
	newPCB.susp = PCB_FLAG_FREE;
	newPCB.memSize = 0;
	newPCB.stackT = "/0";
	newPCB.stackB = "/0";
	newPCB.locAddr = "/0";
	newPCB.excAddr = "/0:; 
}

void allocPCB(){
	struct pcb *temPCB;
	temPCB = &(sys_alloc_mem(PCB_STACK_SIZE));
	return *temPCB;
}


